package org.openstreetmap.gui.jmapviewer;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;

/**
 * Created by: Eduardo Quintana Contreras
 * Date: 11/01/12
 * Time: 06:19 PM
 */
public class MapLabel {

	String labelString;
	String timestamp;
	double lat;
	double lon;
	Font font = new Font("Sans Serif", Font.BOLD, 12);
	Color color, borderColor;

	public MapLabel(String labelString, double lat, double lon) {
		this(Color.BLACK, Color.WHITE, labelString, lat, lon);
	}

	public MapLabel(String labelString, String timestamp, double lat, double lon) {
		this(Color.BLACK, Color.WHITE, labelString, timestamp, lat, lon);
	}

	public MapLabel(Color color, Color borderColor, String labelString, double lat, double lon) {
		this.color = color;
		this.borderColor = borderColor;
		this.labelString = labelString;
		this.lat = lat;
		this.lon = lon;
	}

	public MapLabel(Color color, Color borderColor, String labelString, String timestamp, double lat, double lon) {
		this.color = color;
		this.borderColor = borderColor;
		this.labelString = labelString;
		this.lat = lat;
		this.lon = lon;
		this.timestamp = timestamp;
	}

	public double getLat() {
		return lat;
	}

	public double getLon() {
		return lon;
	}

	public String getLabelString() {
		return labelString;
	}

	public String getTimestamp() {
		return timestamp;
	}

	public void paint(Graphics g, Point position) {
		int x = position.x + 3, y = position.y - 5;
		Graphics2D g2 = (Graphics2D) g;
//		g2.setStroke(new BasicStroke(5f));
//		Font tmpFont = g2.getFont();
		// Remove if slow loading
		g2.setFont(font);
		g2.setColor(borderColor);
		g2.drawString(labelString, ShiftWest(x, 1), ShiftNorth(y, 1));
		g2.drawString(labelString, ShiftWest(x, 1), ShiftSouth(y, 1));
		g2.drawString(labelString, ShiftEast(x, 1), ShiftNorth(y, 1));
		g2.drawString(labelString, ShiftEast(x, 1), ShiftSouth(y, 1));
		g2.setColor(color);
		g2.drawString(labelString, x, y);
//		g2.setFont(tmpFont);
	}

	int ShiftNorth(int p, int distance) {
		return (p - distance);
	}

	int ShiftSouth(int p, int distance) {
		return (p + distance);
	}

	int ShiftEast(int p, int distance) {
		return (p + distance);
	}

	int ShiftWest(int p, int distance) {
		return (p - distance);
	}
}
